package com.lkj.controller;

import cn.hutool.json.JSONUtil;
import com.lkj.common.AjaxResult;
import com.lkj.entity.SysRole;
import com.lkj.entity.SysUser;
import com.lkj.service.SysUserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户信息表(SysUser)表控制层
 *
 * @author makejava
 * @since 2020-09-13 10:39:03
 */
@RestController
@RequestMapping("/sysUser")
public class SysUserController {
    /**
     * 服务对象
     */
    @Resource
    private SysUserService sysUserService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public SysUser selectOne(Long id) {
        return this.sysUserService.queryById(id);
    }


    @GetMapping("/selectList")
    public AjaxResult selectList(){

        List<SysUser> sysUsers = sysUserService.queryAll(null);

        SysUser sysUser = sysUserService.queryById(1L);
        System.out.println(sysUser);

        return AjaxResult.success(sysUsers);

    }


    @GetMapping("/selectRoleListByUserId")
    public AjaxResult selectRoleListByUserId(Long id){

        List<SysRole> sysRoles = sysUserService.selectRoleListByUserId(id);

        return AjaxResult.success(sysRoles);
    }

}